package com.aiyige.base.db.table;

import android.os.Parcel;
import android.os.Parcelable;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import java.util.List;

@DatabaseTable(tableName = "AdModel")
public class AdModel implements Parcelable {
    public static final String ID = "id";
    public static final String AD_ID = "adId";
    public static final String PROGRESS_STATUS = "progressStatus";
    public static final String CONTROL_OPTION = "controlOption";
    public static final String CREATE_TIME = "createTime";
    public static final String AD_STATUS = "adStatus";
    public static final String AD_POSITION = "adPosition";
    public static final String AD_CREATOR = "adCreator";
    public static final String UPDATE_TIME = "updateTime";
    public static final String LAST_PLAY_TIMESTAMP = "lastPlayTimestamp";
    @DatabaseField(id = true, columnName = ID)
    String id;
    @DatabaseField(columnName = AD_ID)
    String adId;
    @DatabaseField(columnName = PROGRESS_STATUS)
    int progressStatus;
    @DatabaseField(columnName = CONTROL_OPTION)
    int controlOption;
    @DatabaseField(columnName = CREATE_TIME)
    long createTime;
    @DatabaseField(columnName = UPDATE_TIME)
    long updateTime;
    @DatabaseField(columnName = AD_STATUS)
    String adStatus;
    @DatabaseField(columnName = AD_POSITION)
    String adPosition;
    @DatabaseField(columnName = AD_CREATOR)
    String creator;
    @DatabaseField
    String adDeployJson;
    @DatabaseField(columnName = LAST_PLAY_TIMESTAMP)
    long lastPlayTimestamp;

    List<AdFile> adFileList;

    public AdModel() {
    }

    private AdModel(Builder builder) {
        setId(builder.id);
        setAdId(builder.adId);
        setProgressStatus(builder.progressStatus);
        setControlOption(builder.controlOption);
        setCreateTime(builder.createTime);
        setUpdateTime(builder.updateTime);
        setAdStatus(builder.adStatus);
        setAdPosition(builder.adPosition);
        setCreator(builder.creator);
        setAdDeployJson(builder.adDeployJson);
        setLastPlayTimestamp(builder.lastPlayTimestamp);
        setAdFileList(builder.adFileList);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getAdId() {
        return adId;
    }

    public void setAdId(String adId) {
        this.adId = adId;
    }

    public int getProgressStatus() {
        return progressStatus;
    }

    public void setProgressStatus(int progressStatus) {
        this.progressStatus = progressStatus;
    }

    public int getControlOption() {
        return controlOption;
    }

    public void setControlOption(int controlOption) {
        this.controlOption = controlOption;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(long updateTime) {
        this.updateTime = updateTime;
    }

    public String getAdStatus() {
        return adStatus;
    }

    public void setAdStatus(String adStatus) {
        this.adStatus = adStatus;
    }

    public String getAdPosition() {
        return adPosition;
    }

    public void setAdPosition(String adPosition) {
        this.adPosition = adPosition;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getAdDeployJson() {
        return adDeployJson;
    }

    public void setAdDeployJson(String adDeployJson) {
        this.adDeployJson = adDeployJson;
    }

    public long getLastPlayTimestamp() {
        return lastPlayTimestamp;
    }

    public void setLastPlayTimestamp(long lastPlayTimestamp) {
        this.lastPlayTimestamp = lastPlayTimestamp;
    }

    public List<AdFile> getAdFileList() {
        return adFileList;
    }

    public void setAdFileList(List<AdFile> adFileList) {
        this.adFileList = adFileList;
    }

    public static final class Builder {
        private String id;
        private String adId;
        private int progressStatus;
        private int controlOption;
        private long createTime;
        private long updateTime;
        private String adStatus;
        private String adPosition;
        private String creator;
        private String adDeployJson;
        private long lastPlayTimestamp;
        private List<AdFile> adFileList;

        private Builder() {
            lastPlayTimestamp = 0;
        }

        public Builder id(String val) {
            id = val;
            return this;
        }

        public Builder adId(String val) {
            adId = val;
            return this;
        }

        public Builder progressStatus(int val) {
            progressStatus = val;
            return this;
        }

        public Builder controlOption(int val) {
            controlOption = val;
            return this;
        }

        public Builder createTime(long val) {
            createTime = val;
            return this;
        }

        public Builder updateTime(long val) {
            updateTime = val;
            return this;
        }

        public Builder adStatus(String val) {
            adStatus = val;
            return this;
        }

        public Builder adPosition(String val) {
            adPosition = val;
            return this;
        }

        public Builder creator(String val) {
            creator = val;
            return this;
        }

        public Builder adDeployJson(String val) {
            adDeployJson = val;
            return this;
        }

        public Builder lastPlayTimestamp(long val) {
            lastPlayTimestamp = val;
            return this;
        }

        public Builder adFileList(List<AdFile> val) {
            adFileList = val;
            return this;
        }

        public AdModel build() {
            return new AdModel(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.adId);
        dest.writeInt(this.progressStatus);
        dest.writeInt(this.controlOption);
        dest.writeLong(this.createTime);
        dest.writeLong(this.updateTime);
        dest.writeString(this.adStatus);
        dest.writeString(this.adPosition);
        dest.writeString(this.creator);
        dest.writeString(this.adDeployJson);
        dest.writeLong(this.lastPlayTimestamp);
        dest.writeTypedList(this.adFileList);
    }

    protected AdModel(Parcel in) {
        this.id = in.readString();
        this.adId = in.readString();
        this.progressStatus = in.readInt();
        this.controlOption = in.readInt();
        this.createTime = in.readLong();
        this.updateTime = in.readLong();
        this.adStatus = in.readString();
        this.adPosition = in.readString();
        this.creator = in.readString();
        this.adDeployJson = in.readString();
        this.lastPlayTimestamp = in.readLong();
        this.adFileList = in.createTypedArrayList(AdFile.CREATOR);
    }

    public static final Creator<AdModel> CREATOR = new Creator<AdModel>() {
        @Override
        public AdModel createFromParcel(Parcel source) {
            return new AdModel(source);
        }

        @Override
        public AdModel[] newArray(int size) {
            return new AdModel[size];
        }
    };
}
